package com.tuo51.childcare.domain.dailyrecord;

import com.tuo51.childcare.domain.vo.DailyGrowRecordOptionVO;
import com.tuo51.childcare.domain.vo.DailyGrowRecordVO;
import com.tuo51.foudation.model.Domain;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.List;

/**
 * 每日观察模板
 */
@Entity
@Table(name = "user_daily_observer_template")
@EqualsAndHashCode(callSuper = true)
@Data
public class DailyGrowRecordTemplate extends Domain {
    @Column(columnDefinition = "int default 0 COMMENT '序号'", nullable = false)
    private Integer dailyIndex = 0;

    @Column(columnDefinition = "int default 0 COMMENT '月龄高'", nullable = false)
    private Integer monthMax = 0;

    @Column(columnDefinition = "int default 0 COMMENT '月龄低'", nullable = false)
    private Integer monthMin = 0;

    @Column(columnDefinition = "int default 0 COMMENT '日龄高'", nullable = false)
    private Integer dayMax = 0;

    @Column(columnDefinition = "int default 0 COMMENT '日龄低'", nullable = false)
    private Integer dayMin = 0;

    @Column(columnDefinition = "varchar(256) COMMENT '字段名'", nullable = false)
    private String title;

    @Column(columnDefinition = "varchar(256) COMMENT '图标'", nullable = false)
    private String icon;

    @Column(columnDefinition = "varchar(256) COMMENT '数据单位'", nullable = false)
    private String unit;

    @Column(columnDefinition = "int default 0 COMMENT '0.数字，1.文字，2.时间 3.时长 4.文件，5.单选，6.多选，7.餐食，8.辅食'", nullable = false)
    private Integer valueType = 0;

    @Type(type = "json")
    @Column(columnDefinition = "JSON COMMENT '选项：名称，value' ")
    private List<DailyGrowRecordOptionVO> options;

    @Column(columnDefinition = " bit DEFAULT 0 COMMENT '可多次提交' ")
    private Boolean repeatable = false;

    @Column(columnDefinition = "varchar(256) COMMENT '备注'", nullable = false)
    private String comment;

    @Transient
    private List<DailyGrowRecordVO> values;

    public static DailyGrowRecordTemplate of(String id, int dailyIndex, String title, int valueType, boolean repeatable){
        DailyGrowRecordTemplate ret = new DailyGrowRecordTemplate();

        ret.setId(id);
        ret.setDailyIndex(dailyIndex);
        ret.setTitle(title);
        ret.setRepeatable(repeatable);

        ret.setValueType(valueType);

        return ret;
    }
}
